//
//  ZHLEEStatusPhotoImageView.swift
//  ZHLEE_Blog_Swift_Pro
//
//  Created by ZHLEEBlander on 15/10/20.
//  Copyright © 2015年 ZHLEEBlander. All rights reserved.
//

import UIKit

class ZHLEEStatusPhotoImageView: UIImageView {
    
    private var gifImageView: UIImageView?
    
    var thumbnail_pic: String? {
    
        didSet{
        
            //判断是否是gif图片
            if let picUrl = thumbnail_pic {
            
                sd_setImageWithURL(NSURL(string: picUrl), placeholderImage: UIImage(named: "timeline_image_placeholder"))
                if picUrl.hasSuffix(".gif"){
                
                    gifImageView?.hidden = false
                }else{
                
                    gifImageView?.hidden = true
                }
            }
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        //设置图片显示的模式
        contentMode = .ScaleAspectFill
        //去除多余的部分
        clipsToBounds = true
        
        //设置gif图标
        let gifImageView = UIImageView(image: UIImage(named: "timeline_image_gif"))
        
        self.gifImageView = gifImageView
        addSubview(gifImageView)
        
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        self.gifImageView!.x = width - self.gifImageView!.width
        self.gifImageView!.y = height - self.gifImageView!.height
    }

}
